#!/bin/bash
# vim: set shiftwidth=4 tabstop=8 noexpandtab:

# Copyright (C) 2018, Osamu Aoki <osamu@debian.org>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# On Debian systems, the complete text of the GNU General Public License
# version 3 can be found in the /usr/share/common-licenses/GPL-3 file.

set -u

TESTTYPE=FTP
. ./lib_test_uscan

DEB_HOST_OS="$(dpkg-architecture -qDEB_HOST_ARCH_OS)"
if [ "$DEB_HOST_OS" = "kfreebsd" ]; then
    # kbsd has a non-working semaphore, that is needed here.
    echo "This test is not supported on $(dpkg-architecture -qDEB_HOST_ARCH), skipping"
    exit 0
fi

COMMAND="uscan --no-conf"

# set safe defaults
WEBSCRIPT=":"
DEBUGECHO=":"
DEBUGLSLR=":"
DEBUGBASH=":"
# comment out for debug
#COMMAND="$COMMAND --debug"
#COMMAND="$COMMAND --verbose"
#DEBUGECHO=echo
#DEBUGLSLR="ls -laR"
#DEBUGLSLR="ls -la"
#DEBUGBASH="bash -i"

# Initial Debian revision value is distribution dependent
SUFFIX="1"
if command -v dpkg-vendor >/dev/null; then
    VENDER="$(dpkg-vendor --query Vendor 2>/dev/null|tr 'A-Z' 'a-z')"
    case "$VENDER" in
        debian) SUFFIX="1" ;;
        *) SUFFIX="0${VENDER}1" ;;
    esac
fi

cleanup(){
    kill -9 $(cat $TMPDIR/$REPOPATH/pid)
    rm -rf $TMPDIR
    echo ""
}

spawnFtpServer(){
    (
        local USCAN_FTP_SERVER=${USCAN_FTP_SERVER:-ftpserver.py}
        mkdir -p "$TMPDIR/$REPOPATH"
        cd "$TMPDIR/$REPOPATH" || exit 1
        echo "FTP starting ... $TMPDIR/$REPOPATH"
        local pid
        python3 "$test_dir/uscan/$USCAN_FTP_SERVER" 2>log &
        pid=$!
        echo $pid > pid
        while ! [ -s port ]; do
            sleep 2s
            if ! kill -0 $pid 2> /dev/null ; then
                echo "The FTP server returned an error:"
                cat log
                exit 1
            fi
        done
    )
}

trap cleanup 1 2 3 13 15

containsName(){
  echo "$1" | grep -qF "$2"
  echo $?
}

. "${0%/*}/shunit2-helper-functions.sh"

# The following tests do the following: (1) create a minimal Debian package
# directory, containing minimal files debian/{changelog,watch,copyright},
# (2) create a minimal repository, containing a tarball (built on the fly),
# (3) start an FTP server that works offline, using the pyftpdlib
# module of Python, and (4) run uscan inside that minimal universe.

# make debian/ in `pwd`
# debian/watch contains $WATCHVER and $WATCHLINE with template URL updated
makeDebianDir() {
    DEBNAME=${1:-foo} # Debian source package name
    DEBVER=${2:-1.0}  # Debian source package version
    mkdir -p debian/source

    cat <<END > debian/rules
%:
        dh $@
END
chmod 755 debian/rules

    cat <<END > debian/changelog
$DEBNAME ($DEBVER) unstable; urgency=low

  * Release of the $DEBNAME package $DEBVER.

 -- Joe Developer <jd@debian.org>  Mon, 02 Nov 2013 22:21:31 -0100
END
    # debian/source/format
    case $DEBVER in
        *-*) # non-native package
            echo "3.0 (quilt)" > debian/source/format
             ;;
        *) # native package
            echo "3.0 (native)" > debian/source/format
             ;;
    esac
    # debian/copyright
    echo "Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/" \
        > debian/copyright
    # debian/watch
    echo "version=$WATCHVER" > debian/watch
    echo "$WATCHLINE" | sed -e "s,@@@url@@@,ftp://127.0.0.1:${PORT}/,g" - \
        >> debian/watch
    # debian/upstream/signing-key.asc
    mkdir -p debian/upstream
    cp -f $test_dir/uscan/PUBLIC_KEY.asc debian/upstream/signing-key.asc
}


# make tarball in $REPOPATH/$POOLPATH
makeUpstreamTar() {
    UPNAME=${1:-foo} # Upstream package name
    UPVER=${2:-1.0}  # upstream package version
    COMPRESSION=${3:-gz} # archive compression type
    TYPE=${4:-non-native} # set this if native-type upstream
    OLDDIR=`pwd`
    mkdir -p $TMPDIR/$REPOPATH/$POOLPATH/$UPNAME-$UPVER
    cd $TMPDIR/$REPOPATH/$POOLPATH
    touch $UPNAME-$UPVER/FILE.$UPNAME.$UPVER
    if [ "$TYPE" = "native" ]; then
        cd $TMPDIR/$REPOPATH/$POOLPATH/$UPNAME-$UPVER
        makeDebianDir $UPNAME $UPVER
        cd $TMPDIR/$REPOPATH/$POOLPATH
    fi
    case $COMPRESSION in
        gz|gzip)
            NEWTAR=$UPNAME-$UPVER.tar
            tar -cf $NEWTAR $UPNAME-$UPVER
            NEWTAR=$UPNAME-$UPVER.tar.gz
            tar -czf $NEWTAR $UPNAME-$UPVER
            ;;
        bz2|bzip2)
            NEWTAR=$UPNAME-$UPVER.tar
            tar -cf $NEWTAR $UPNAME-$UPVER
            NEWTAR=$UPNAME-$UPVER.tar.bz2
            tar --bzip2 -cf $NEWTAR $UPNAME-$UPVER
            ;;
        xz)
            NEWTAR=$UPNAME-$UPVER.tar
            tar -cf $NEWTAR $UPNAME-$UPVER
            NEWTAR= $UPNAME-$UPVER.tar.xz
            tar --xz -cf $NEWTAR $UPNAME-$UPVER
            ;;
        zip)
            NEWTAR=$UPNAME-$UPVER.zip
            zip -r $NEWTAR $UPNAME-$UPVER
            ;;
        *)  echo "Wrong compression mode: $COMPRESSION"
            exit 1
            ;;
    esac
    # make $NEWTAR.asc
    $GPG --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \
        --default-key 72543FAF \
        --armor --detach-sign $NEWTAR
    if [ "$COMPRESSION" != "zip" ]; then
        NEWTAR=$UPNAME-$UPVER.tar
        $GPG --homedir "$GPGHOME" --no-options -q --batch --no-default-keyring \
          --default-key 72543FAF \
          --armor --detach-sign $NEWTAR

    fi
    cd $OLDDIR
}

# setup a common watch file test environment
helperWatch() {
    local SITESCRIPT=${1:-siteWebNonNative}
    local VEROLD=${2:-1.0}
    local VERNEW=${3:-2.0}
    local PREFIX="${4:-}"
    local TMPDIR=$(mktemp -d)
    ORIGDIR=`pwd`
    PKG=${PKG:-foo}
    REPOPATH=${REPOPATH:-repo}
    POOLPATH=${POOLPATH:-pool}
    GZREPACK=${GZREPACK:-gz}
    XCOMMAND=${XCOMMAND:-$COMMAND}
    WATCHVER="${WATCHVER:-3}"
    WATCHLINE0="@@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate"
    WATCHLINE="${WATCHLINE:-$WATCHLINE0}"
    cd $TMPDIR
    # start FTP server with its root at $TMPDIR/$REPOPATH
    spawnFtpServer || exit 1
    PORT=$(cat $TMPDIR/$REPOPATH/port)
    $DEBUGECHO " ***** ftp://localhost:$PORT started showing $TMPDIR/$REPOPATH *****"
    # make web site
    $SITESCRIPT
    # make local $VEROLD source tree
    tar -xzf $TMPDIR/$REPOPATH/$POOLPATH/${PKG}-${VEROLD}.tar.gz
    if [ -n "${PREFIX}" ]; then
        mv $TMPDIR/${PKG}-${VEROLD} $TMPDIR/${PKG}-${PREFIX}${VEROLD}
    fi
    mv $TMPDIR/${PKG}-${PREFIX}${VEROLD} $TMPDIR/${PKG}
    cd $TMPDIR/${PKG}
    if [ ! -d debian ]; then
        makeDebianDir $PKG ${PREFIX}${VEROLD}-$SUFFIX
    fi
    local UUPDATE=""
    if grep -q "uupdate" $TMPDIR/${PKG}/debian/watch ; then
        UUPDATE=uupdate
    fi
    local PGP=""
    if grep -q "pgpurlmangle" $TMPDIR/${PKG}/debian/watch ; then
        PGP=pgp
    fi
    if grep -q "pgpmode *= *auto" $TMPDIR/${PKG}/debian/watch ; then
        PGP=pgp
    fi
    if grep -q "pgpmode *= *previous" $TMPDIR/${PKG}/debian/watch ; then
        PGP=pgp
    fi
    $XCOMMAND
    assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0"
    cd $TMPDIR
    $DEBUGLSLR
    UTARBALL=${PKG}-${VERNEW}.tar.gz
    STARBALL=${PKG}_${PREFIX}${VERNEW}.orig.tar.$GZREPACK
    assertTrue "$UTARBALL missing: $WATCHLINE" "[ -f $UTARBALL ]"
    assertTrue "$STARBALL missing: $WATCHLINE" "[ -f $STARBALL ]"
    if [ "$PGP" = "pgp" ]; then
        UTARSIG=${PKG}-${VERNEW}.tar.gz.asc
        if [ ! -f $UTARSIG ]; then
            UTARSIG=${PKG}-${VERNEW}.tar.asc
        fi
        STARSUG=${PKG}_${PREFIX}${VERNEW}.orig.tar.$GZREPACK.asc
        assertTrue "$UTARSIG and *.sig missing: $WATCHLINE" "[ -f $UTARSIG ]"
        assertTrue "$STARSIG missing: $WATCHLINE" "[ -f $STARSIG ]"
    fi
    # check uupdate
    if [ "$UUPDATE" = "uupdate" ]; then
        cd $TMPDIR/${PKG}-${PREFIX}${VERNEW}
        assertTrue 'pristine tarball is not extracted' "[ -f debian/changelog ]"
        DVERSION=`dpkg-parsechangelog -ldebian/changelog -SVersion`
        assertEquals "uscan: Version should be ${PREFIX}${VERNEW}-$SUFFIX but $DVERSION" "$DVERSION" "${PREFIX}${VERNEW}-$SUFFIX"
        cd $TMPDIR
    fi
    $DEBUGBASH
    cd $ORIGDIR
    cleanup
    unset REPOPATH
    unset POOLPATH
    unset GZREPACK
    unset XCOMMAND
    unset WATCHVER
    unset WATCHLINE
}

# setup a common watch file test environment with Zip upstream
helperWatchZip() {
    local SITESCRIPT=${1:-siteWebNonNative}
    local VEROLD=${2:-1.0}
    local VERNEW=${3:-2.0}
    local PREFIX="${4:-}"
    local TMPDIR=$(mktemp -d)
    ORIGDIR=`pwd`
    PKG=${PKG:-foo}
    REPOPATH=${REPOPATH:-repo}
    POOLPATH=${POOLPATH:-pool}
    GZREPACK=${GZREPACK:-xz}
    XCOMMAND=${XCOMMAND:-$COMMAND}
    WATCHVER="${WATCHVER:-3}"
    WATCHLINE0="@@@url@@@/ (?:.*)/@PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate"
    WATCHLINE="${WATCHLINE:-$WATCHLINE0}"
    cd $TMPDIR
    # start FTP server with its root at $TMPDIR/$REPOPATH
    spawnFtpServer || exit 1
    PORT=$(cat $TMPDIR/$REPOPATH/port)
    $DEBUGECHO " ***** ftp://localhost:$PORT started showing $TMPDIR/$REPOPATH *****"
    # make web site
    $SITESCRIPT
    # make local $VEROLD source tree
    unzip $TMPDIR/$REPOPATH/$POOLPATH/${PKG}-${VEROLD}.zip
    if [ -n "$PREFIX" ]; then
        mv $TMPDIR/${PKG}-${VEROLD} $TMPDIR/${PKG}-${PREFIX}${VEROLD}
    fi
    mv $TMPDIR/${PKG}-${PREFIX}${VEROLD} $TMPDIR/${PKG}
    cd $TMPDIR/${PKG}
    if [ ! -d debian ]; then
        makeDebianDir $PKG ${PREFIX}${VEROLD}-$SUFFIX
    fi
    local UUPDATE=""
    if grep -q "uupdate" $TMPDIR/${PKG}/debian/watch ; then
        UUPDATE=uupdate
    fi
    local PGP=""
    if grep -q "pgpurlmangle" $TMPDIR/${PKG}/debian/watch ; then
        PGP=pgp
    fi
    if grep -q "pgpmode *= *auto" $TMPDIR/${PKG}/debian/watch ; then
        PGP=pgp
    fi
    if grep -q "pgpmode *= *previous" $TMPDIR/${PKG}/debian/watch ; then
        PGP=pgp
    fi
    $XCOMMAND
    assertEquals "uscan: exit_code!=0 but exit_code=0" "$?" "0"
    cd $TMPDIR
    $DEBUGLSLR
    UTARBALL=${PKG}-${VERNEW}.zip
    STARBALL=${PKG}_${PREFIX}${VERNEW}.orig.tar.$GZREPACK
    assertTrue "$UTARBALL missing: $WATCHLINE" "[ -f $UTARBALL ]"
    assertTrue "$STARBALL missing: $WATCHLINE" "[ -f $STARBALL ]"
    if [ "$PGP" = "pgp" ]; then
        UTARSIG=${PKG}-${VERNEW}.zip.asc
        STARSUG=${PKG}_${PREFIX}${VERNEW}.orig.tar.$GZREPACK.asc
        assertTrue "$UTARSIG and *.sig missing: $WATCHLINE" "[ -f $UTARSIG ]"
        assertTrue "$STARSIG missing: $WATCHLINE" "[ -f $STARSIG ]"
    fi
    # check uupdate
    if [ "$UUPDATE" = "uupdate" ]; then
        cd $TMPDIR/${PKG}-${PREFIX}${VERNEW}
        assertTrue 'pristine tarball is not extracted' "[ -f debian/changelog ]"
        DVERSION=`dpkg-parsechangelog -ldebian/changelog -SVersion`
        assertEquals "uscan: Version should be ${PREFIX}${VERNEW}-$SUFFIX but $DVERSION" "$DVERSION" "${PREFIX}${VERNEW}-$SUFFIX"
        cd $TMPDIR
    fi
    $DEBUGBASH
    cd $ORIGDIR
    cleanup
    unset REPOPATH
    unset POOLPATH
    unset GZREPACK
    unset XCOMMAND
    unset WATCHVER
    unset WATCHLINE
}

siteNonNative() {
    local PKG=${1:-foo}
    local EXTRA=${2:-}
    makeUpstreamTar $PKG 0.0 gz non-native
    makeUpstreamTar $PKG 1.0 gz non-native
    makeUpstreamTar $PKG 2.0 gz non-native
    mkdir -p $TMPDIR/$REPOPATH/0.0/$PKG/ooo/
    mkdir -p $TMPDIR/$REPOPATH/1.0/$PKG/ooo/
    mkdir -p $TMPDIR/$REPOPATH/2.0/$PKG/ooo/
    if [ -n "$EXTRA" ]; then
    makeUpstreamTar $PKG 3.0 gz non-native
    mkdir -p $TMPDIR/$REPOPATH/3.0/$PKG/ooo/
    fi
    ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.gz
    ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz.asc $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.gz.asc
    ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.asc $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.tar.asc
    ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.gz
    ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz.asc $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.gz.asc
    ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.asc $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.tar.asc
    ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.gz
    ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz.asc $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.gz.asc
    ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.asc $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.tar.asc
    if [ -n "$EXTRA" ]; then
    ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.tar.gz
    ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz.asc $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.tar.gz.asc
    ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.asc $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.tar.asc
    fi
}

siteNonNativeZip() {
    local PKG=${1:-foo}
    local EXTRA=${2:-}
    makeUpstreamTar $PKG 0.0 zip non-native
    makeUpstreamTar $PKG 1.0 zip non-native
    makeUpstreamTar $PKG 2.0 zip non-native
    mkdir -p $TMPDIR/$REPOPATH/0.0/$PKG/ooo/
    mkdir -p $TMPDIR/$REPOPATH/1.0/$PKG/ooo/
    mkdir -p $TMPDIR/$REPOPATH/2.0/$PKG/ooo/
    if [ -n "$EXTRA" ]; then
    makeUpstreamTar $PKG 3.0 gz non-native
    mkdir -p $TMPDIR/$REPOPATH/3.0/$PKG/ooo/
    fi
    ln -sf ../../../$POOLPATH/${PKG}-0.0.zip $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.zip
    ln -sf ../../../$POOLPATH/${PKG}-0.0.zip.asc $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-0.0.zip.asc
    ln -sf ../../../$POOLPATH/${PKG}-1.0.zip $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.zip
    ln -sf ../../../$POOLPATH/${PKG}-1.0.zip.asc $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-1.0.zip.asc
    ln -sf ../../../$POOLPATH/${PKG}-2.0.zip $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.zip
    ln -sf ../../../$POOLPATH/${PKG}-2.0.zip.asc $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-2.0.zip.asc
    if [ -n "$EXTRA" ]; then
    ln -sf ../../../$POOLPATH/${PKG}-3.0.zip $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.zip
    ln -sf ../../../$POOLPATH/${PKG}-3.0.zip.asc $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-3.0.zip.asc
    fi
}

siteNonNativeR() {
    local PKG=${1:-foo}
    local EXTRA=${2:-}
    makeUpstreamTar $PKG 0.0 gz non-native
    makeUpstreamTar $PKG 1.0 gz non-native
    makeUpstreamTar $PKG 2.0 gz non-native
    mkdir -p $TMPDIR/$REPOPATH/0.0/$PKG/ooo/
    mkdir -p $TMPDIR/$REPOPATH/1.0/$PKG/ooo/
    mkdir -p $TMPDIR/$REPOPATH/2.0/$PKG/ooo/
    if [ -n "$EXTRA" ]; then
    makeUpstreamTar $PKG 3.0 gz non-native
    mkdir -p $TMPDIR/$REPOPATH/3.0/$PKG/ooo/
    fi
    ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-0.0.tar.gz
    ln -sf ../../../$POOLPATH/${PKG}-0.0.tar.gz.asc $TMPDIR/$REPOPATH/3.0/$PKG/ooo/${PKG}-0.0.tar.gz.asc
    ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-1.0.tar.gz
    ln -sf ../../../$POOLPATH/${PKG}-1.0.tar.gz.asc $TMPDIR/$REPOPATH/2.0/$PKG/ooo/${PKG}-1.0.tar.gz.asc
    ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-2.0.tar.gz
    ln -sf ../../../$POOLPATH/${PKG}-2.0.tar.gz.asc $TMPDIR/$REPOPATH/1.0/$PKG/ooo/${PKG}-2.0.tar.gz.asc
    if [ -n "$EXTRA" ]; then
    ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-3.0.tar.gz
    ln -sf ../../../$POOLPATH/${PKG}-3.0.tar.gz.asc $TMPDIR/$REPOPATH/0.0/$PKG/ooo/${PKG}-3.0.tar.gz.asc
    fi
}

# test a watch files

### VERSION 4 ###
# standard tests

# test non-native package with uupdate, bare FTP server in normal order
testWatch4NonNative() {
    WATCHVER=4
    WATCHLINE='opts=pgpsigurlmangle=s/$/.asc/ @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate'
    helperWatch siteNonNative
}

# test --download-current-version, bare FTP server in normal order
testWatch4NonNativeDlCurrent() {
    WATCHVER=4
    XCOMMAND="$COMMAND --download-current-version"
    WATCHLINE='opts=pgpsigurlmangle=s/$/.asc/ @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate'
    helperWatch siteNonNative 1.0 1.0
}

# test --download-version, bare FTP server in normal order
testWatch4NonNativeDlUversion() {
    WATCHVER=4
    XCOMMAND="$COMMAND --download-version 0.0"
    WATCHLINE='opts=pgpsigurlmangle=s/$/.asc/ @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate'
    helperWatch siteNonNative 1.0 0.0
}

# test non-native package with uupdate, bare FTP server in normal order with upstream ZIP
testWatch4NonNativeZip() {
    WATCHVER=4
    COMPRESSION='zip'
    WATCHLINE='opts=pgpsigurlmangle=s/$/.asc/ @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate'
    helperWatchZip siteNonNativeZip
}

# test non-native package with uupdate, bare FTP server in normal order with repack to xz
testWatch4NonNativeXz() {
    WATCHVER=4
    GZREPACK='xz'
    WATCHLINE='opts=pgpsigurlmangle=s/$/.asc/,compression=xz,repack @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate'
    helperWatch siteNonNative
}

# test non-native package with uupdate, bare FTP server in normal order with ungzsig
testWatch4NonNativeUngzsig() {
    WATCHVER=4
    WATCHLINE='opts=pgpsigurlmangle=s/.gz$/.asc/,decompress @@@url@@@([\.\d]+)/(.+)/(.+)/ @PACKAGE@@ANY_VERSION@@ARCHIVE_EXT@ debian uupdate'
    helperWatch siteNonNative
}

. shunit2
